<?php
/**
 * 积分管理
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');
class member_goodsbrowseControl extends BaseMemberControl {

	public function __construct() {
		parent::__construct();
		/**
		 * 读取语言包
		 */
		Language::read('member_member_points');
		Language::read('member_pointorder');

	}
	/**
	 * 积分日志列表
	 */
	public function listOp(){
		//分页
		$page	= new Page();
		$page->setEachNum(20);
		$page->setStyle('admin');
		$model_goodsbrowse = Model('goodsbrowse');
        $condition = array();
        $condition['member_id'] = $_SESSION['member_id'];
        $goodsbrowse_list = $model_goodsbrowse->getGoodsBrowseList($condition, $page);
		if (!empty($goodsbrowse_list) && is_array($goodsbrowse_list)){
			$goodsbrowse_id = array();//足迹的商品编号
			foreach ($goodsbrowse_list as $key=>$goodsbrowse){
				$goods_id = $goodsbrowse['goods_id'];
				$goodsbrowse_id[] = $goodsbrowse['goods_id'];
				$goodsbrowse_key[$goods_id] = $key;
			}
			$goods_model = Model('goods');
			$goods_list = $goods_model->getGoodsList(array('goods_id' => array('in', $goodsbrowse_id)), 'goods_id,goods_name,goods_image,goods_price,goods_marketprice');
			if (!empty($goods_list) && is_array($goods_list)){
				foreach ($goods_list as $key=>$goodsbrowse){
					$goods_id = $goodsbrowse['goods_id'];
					$goodsbrowse['goods_member_id'] = $goodsbrowse['member_id'];
					$key = $goodsbrowse_key[$goods_id];
					$goodsbrowse_list[$key]['goods'] = $goodsbrowse;
				}
			}
		}
		Tpl::output('goodsbrowse_list',$goodsbrowse_list);
				
        Tpl::output('show_page', $page->show()) ;
        $this->profile_menu('goodsbrowse');
		Tpl::showpage('member_goodsbrowse');
	}
	
	/**
	 * 积分日志列表
	 */
	public function delOp(){
		$model_goodsbrowse = Model('goodsbrowse');
		$goods_id = $_GET['goods_id'];
		if ($goods_id == 'all'){
			$condition = array();
			$condition['member_id'] = $_SESSION['member_id'];
			$model_goodsbrowse->delGoodsBrowse($condition);
		} else {
			$condition = array();
			$condition['goods_id'] = $goods_id;
			$condition['member_id'] = $_SESSION['member_id'];
			$model_goodsbrowse->delGoodsBrowse($condition);
		}

	}
    /**
     * 用户中心右边，小导航
     *
     * @param string	$menu_type	导航类型
     * @param string 	$menu_key	当前导航的menu_key
     * @param array 	$array		附加菜单
     * @return
     */
    private function profile_menu($menu_key='') {
        $menu_array = array(
            array('menu_key'=>'goodsbrowse','menu_name'=>'我的足迹','menu_url'=>'index.php?act=member_goodsbrowse&op=list')
        );
        Tpl::output('member_menu',$menu_array);
        Tpl::output('menu_key',$menu_key);
    }
}
